﻿@{
    Layout = null;
}
@{  Html.Telerik().Window()
            .Name("MessageBox")
            .Title("Message!")
            .Draggable(true)
            .Resizable(resizing => resizing
                .Enabled(false)
                .MinHeight(250)
                .MinWidth(250)
                .MaxHeight(500)
                .MaxWidth(500)
            )
            .ClientEvents(events => events.OnLoad("winOnLoad").OnClose("winOnClose"))
            .Modal(true)
            .Width(300)
            .Height(100)
            .Visible(false)
            .Buttons(b => b.Maximize().Close())
            .Content(@<text>
                            <p style="text-align: center">
                                ...
                            </p>
                     </text>)
            .Buttons( button => button.Close())
            .Render();
}

<script type="text/javascript" language="javascript">

    function winOnLoad() {
        // code here
    }

    function winOnClose() {
        return true;
    }

    var messageTemplate = '<p style="text-align: center">{i}<br /><br />{m}<br/><input type="button" class="wClose" value="Close" onclick="closeWin();" /></p>';
    var errorMessageTemplate = messageTemplate.replace("{i}", '<img alt="error" src="@Url.Content("~/content/themes/admin/img/msgbox/error.png")" />');
    var informationMessageTemplate = messageTemplate.replace("{i}", '<img alt="error" src="@Url.Content("~/content/themes/admin/img/msgbox/information.png")" />');

    function genereateMessage(_content, _isError) {
        if (_isError) {
            return errorMessageTemplate.replace("{m}", _content);
        }
        else {
            return informationMessageTemplate.replace("{m}", _content);
        }
    }

    function OpenPopup(_title, _content, _isError , _width, _height) {
        var popup = $('#MessageBox').data('tWindow');
        popup.title(_title);
        popup.content(genereateMessage(_content, _isError));

        if (_width) {
            popup.width = _width;
        }
        else {
            popup.width = 300;
        }
        if (_height) {
            popup.height = _height;
        }
        else {
            popup.height = 300;
        }

        popup.center();
        popup.open();
    }

    function closeWin() {
        var window = $("#MessageBox").data("tWindow");
        window.close();
    }
</script>